<?php
class b2c_mdl_analysis_chongzhi extends b2c_mdl_member_shenhe{
    public function table_name($real=false){
        $table_name = 'member_shenhe';
        if($real){
            return kernel::database()->prefix.'b2c_'.$table_name;
        }else{
            return $table_name;
        }
    }

    public function chongzhi_money($filter=null){
        //存入金额,支出金额
        $sql = 'SELECT sum(import_money) as import_money FROM '.
            $this->table_name(true).' WHERE '.
            'mtime >='.$filter['time_from'].' and mtime <='.intval($filter['time_to']).' and disabled = \'false\'';

        $row = $this->db->select($sql);
        return $row[0];
    }

    public function shenhe_money($filter=null){
        //存入金额,支出金额
        $sql = 'SELECT sum(import_money) as import_money FROM '.
            $this->table_name(true).' WHERE '.
            'mtime >='.$filter['time_from'].' and mtime <='.intval($filter['time_to']).' and is_shenhe = \'1\' and disabled = \'false\'';

        $row = $this->db->select($sql);
        return $row[0];
    }

    public function _filter($filter,$tableAlias=null,$baseWhere=null){
        $where=array(1);

        if(isset($filter['time_from']) && $filter['time_from']){
            $where[] = ' mtime >='.strtotime($filter['time_from']);
        }
        if(isset($filter['time_to']) && $filter['time_to']){
            $where[] = ' mtime <'.(strtotime($filter['time_to'])+86400);
        }

        return parent::_filter($filter).' and '.implode($where,' AND ');
    }
}
